﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>修改密码</title>
    <#include "/common/link.ftl">

</head>
<body class="hold-transition skin-black sidebar-mini">
<div class="wrapper">
    <#include "/common/navbar.ftl">
    <#assign currentMenu="employee"/>
    <#include "/common/menu.ftl">
    <div class="content-wrapper">
        <section class="content-header">
            <h1>修改密码</h1>
        </section>
        <section class="content">
            <div class="box">
                <form class="form-horizontal" action="#" method="post" id="editForm">
                    <div class="form-group" style="margin-top: 10px;">
                        <label class="col-sm-2 control-label">原密码：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="oldpassword" placeholder="请输入原密码">
                        </div>
                    </div>
                    <div class="form-group" style="margin-top: 10px;">
                        <label class="col-sm-2 control-label">新密码：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="newpassword" placeholder="请输入新密码">
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-sm-offset-1 col-sm-6">
                            <button type="button" class="btn btn-primary btn-submit">保存</button>
                            <a href="javascript:window.history.back()" class="btn btn-danger">取消</a>
                        </div>
                    </div>

                </form>

            </div>
        </section>
    </div>
    <#include "/common/footer.ftl">
</div>
<script>
    $(document).ready(function () {
        $('#editForm').bootstrapValidator({
            message: 'This value is not valid',
//        live: 'disabled',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                oldpassword: {
                    validators: {
                        notEmpty: {
                            message: '旧密码不能为空'
                        },
                    }
                },

                newpassword: {
                    validators: {
                        notEmpty: {
                            message: '密码不可为空'
                        },
                        different: {
                            field: 'oldpassword',
                            message: '新旧密码不可一致'
                        }
                    }
                },
                country: {
                    validators: {
                        notEmpty: {
                            message: 'The country is required and can\'t be empty'
                        }
                    }
                }
            }
        }).on(
            $('.btn-submit').click(function () {
                $.post("/employee/UpdatePassword", $("#editForm").serialize(), function (data) {
                    if (data.success) {
                        Swal.fire({
                            icon: 'success',
                            title: "操作成功",
                            confirmButtonText: "确认",
                        }).then((result) => {
                            window.location.href = '/employee/list';
                        })
                    } else {
                        Swal.fire(
                            '操作失败!',
                            data.msg,
                            'error'
                        ).then((result) =>{
                            window.location.reload();
                            }
                        )
                    }
                })
            })
        );
    });
</script>
</body>
</html>
